package com.jk.smartelderlycare.controller;

import com.jk.smartelderlycare.dto.SysLabel;
import com.jk.smartelderlycare.pojo.PagedResponse;
import com.jk.smartelderlycare.pojo.ResponseResult;
import com.jk.smartelderlycare.security.LoginUser;
import com.jk.smartelderlycare.service.SysLabelServiceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author hhk
 * @version 1.0
 * @ClassName SysLabelController
 * @program: smart-elderly-care
 * @description: TODO
 * @date 2024/11/14 15:42
 */
@Api(tags = "标签管理模块")
@RestController
@CrossOrigin
@RequestMapping(value = "sysLabel")
public class SysLabelController {
    @Autowired
    private SysLabelServiceFeign sysLabelServiceFeign;
    /** 
     * @description: 标签后端分页查询
     * @param: []
     * @return: com.jk.smartelderlycare.pojo.ResponseResult<com.jk.smartelderlycare.pojo.PagedResponse<com.jk.smartelderlycare.dto.SysLabel>>
     * @author hhk
     * @date: 2024/11/14 15:44
     */ 
    @ApiOperation(value = "标签后端分页查询",httpMethod = "POST",notes = "标签后端分页查询")
    @PostMapping(value = "findSysLabelPagimationList")
    private ResponseResult<PagedResponse<SysLabel>> findSysLabelPagimationList(@RequestBody SysLabel sysLabel, @RequestParam(value = "pageNum") Integer pageNum, @RequestParam(value = "pageSize") Integer pageSize){
       return new ResponseResult<>(200,"查询成功",sysLabelServiceFeign.findSysLabelPagimationList(sysLabel,pageNum,pageSize)); 
    }
    /** 
     * @description: 新增标签
     * @param: [sysLabel]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/14 15:47
     */ 
    @ApiOperation(value = "新增标签",httpMethod = "POST",notes = "新增标签")
    @PostMapping(value = "addSysLabel")
    private ResponseResult addSysLabel(@RequestBody SysLabel sysLabel){
        try {
            sysLabelServiceFeign.addSysLabel(sysLabel);
            return new ResponseResult(200,"新增成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"新增失败");
        }

    }
    /** 
     * @description: 根据id删除标签
     * @param: [labelId]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/14 15:48
     */ 
    @ApiOperation(value = "根据id删除标签",httpMethod = "DELETE",notes = "根据id删除标签")
    @DeleteMapping(value = "deleteSysLabelByLabelId")
    private ResponseResult deleteSysLabelByLabelId(@RequestParam Long labelId){
        try {
            sysLabelServiceFeign.deleteSysLabelByLabelId(labelId);
            return new ResponseResult(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"删除失败");
        }

    }
    /** 
     * @description: 根据id查询标签
     * @param: [labelId]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/14 15:49
     */ 
    @ApiOperation(value = "根据id查询标签",httpMethod = "GET",notes = "根据id查询标签")
    @GetMapping(value = "findSysLabelByLabelId")
    private ResponseResult findSysLabelByLabelId(@RequestParam Long labelId){
        return new ResponseResult(200,"查询成功",sysLabelServiceFeign.findSysLabelByLabelId(labelId));
    }
    /** 
     * @description: 修改标签
     * @param: [sysLabel]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/14 15:50
     */ 
    @ApiOperation(value = "修改标签",httpMethod = "PUT",notes = "修改标签")
    @PutMapping(value = "updataSysLabel")
    private ResponseResult updataSysLabel(@RequestBody SysLabel sysLabel){
        try {
            LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            sysLabel.setModifyTime(new Date());
            sysLabel.setModifyUser(loginUser.getUser().getUserName());
            sysLabelServiceFeign.updataSysLabel(sysLabel);
            return new ResponseResult(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"修改失败");
        }

    }
    /** 
     * @description: 修改标签状态
     * @param: [sysLabel]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/14 19:17
     */ 
    @ApiOperation(value = "修改标签状态",httpMethod = "PUT",notes = "修改标签状态")
    @PutMapping(value = "updateStatus")
    private ResponseResult updateStatus(@RequestBody SysLabel sysLabel){
        try {
            sysLabelServiceFeign.updateStatus(sysLabel);
            return new ResponseResult(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"修改失败");
        }

    }
    
    
    
}
